package tech.xs.common.domain.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import tech.xs.common.framework.domain.annotations.ChildDict;
import tech.xs.common.framework.domain.annotations.ChildDictData;
import tech.xs.common.framework.domain.annotations.Dict;
import tech.xs.common.framework.domain.annotations.DictData;
import tech.xs.common.framework.domain.constant.ModuleNames;
import tech.xs.common.framework.domain.enums.BaseEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用性别枚举
 *
 * @author 沈家文
 * @since 2023/6/21 16:42
 */
@Dict(code = "Sex", name = "性别", module = ModuleNames.COMMON,
        children = {
                @ChildDict(code = "Secrecy", name = "性别"),
        }
)
public enum SexEnum implements BaseEnum {


    /**
     * 0 未知
     */
    @DictData(name = "未知", order = 10,
            children = {
                    @ChildDictData(childCode = "Secrecy", name = "保密")
            }
    )
    UNKNOWN(0),

    /**
     * 男
     */
    @DictData(name = "男", order = 20,
            children = {
                    @ChildDictData(childCode = "Secrecy", name = "男")
            })
    MAN(1
    ),

    /**
     * 女
     */
    @DictData(name = "女", order = 30,
            children = {
                    @ChildDictData(childCode = "Secrecy", name = "女")
            }
    )
    WOMAN(2);

    @EnumValue
    @JsonValue
    private final int value;

    private static final Map<Integer, SexEnum> mappings = new HashMap<>(values().length);

    static {
        for (SexEnum item : values()) {
            mappings.put(item.getValue(), item);
        }
    }

    SexEnum(int value) {
        this.value = value;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static SexEnum create(int value) {
        return mappings.get(value);
    }

    @Override
    public Integer getValue() {
        return value;
    }

}
